const { games, tool, layers, Uiwindow } = require('./example/create');
const listener = require('./listener/listener');
const init = require('./example/init');

// 底下为开始
let blueObj = {
    'road': './sources/images/map/blue/blue_tileA_0403_bottom.png',
    'npc': './sources/images/test/duducg1 (53).png',
    'sword': './sources/images/test/wep_sw014_结果.png',
};
let complete = tool.add({ ...blueObj }).loadImages();

let animationFrame = null;

// 主循环
const mainLoop = () => {
    // let tiledMap1 = new TiledMap(tiledarr);
    // let map1 = new Maps('map1', games.tiledImg, 2400, 2400, 28, 28, 2400 / 30, 2400 / 30);
    // map1.randomGeneration(tiledMap1, roadnames).drawBg(games.ctx, '#051529').draw(games.ctx);
    // map1.randomGeneration(tiledMap1, roadnames)
    // layers.add('map', 1, () => map1.draw(games.ctx)).add('bg', 0, () => map1.drawBg(games.ctx, '#051529')).run();

    Uiwindow.add(games, layers).selectRole(games.npc).open();
    Uiwindow.drawTopBar();
    games.draw(layers);
    // 事件监听
    listener();
}

let run = () => {
    animationFrame = requestAnimationFrame(run);
    mainLoop();
}

complete.then(res => {
    if (res) {
        init();
        run();
    }
})